package com.tlgen.modules.vocation.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tlgen.modules.common.domain.J_Area;
import com.tlgen.modules.system.domain.CSort;
import com.tlgen.modules.common.domain.Nation;
import com.tlgen.modules.common.domain.Position;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;

/**
 * @author: tlgen
 * @Discription:
 */
@Entity
@Data
@Table(name = "home")
public class Home {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = {Home.Update.class})
    private Long id;

    public @interface Update {}

    /**
     * 家庭成员所对应的的家庭户主
     */
    @ManyToMany(mappedBy = "homes")
    @JsonIgnore
    private Set<Family> families;

    /**
     * 户内编号
     */
    @Column(name = "code")
    @NotBlank
    private String code;

    /**
     * 户主姓名
     */
    @Column(name = "name")
    @NotBlank
    private String name;

    /**
     * 身份证号
     */
    @Column(name = "card")
    @NotBlank
    private String card;

    /**
     * 性别
     */
    @Column(name = "sex")
    private Integer sex;

    /**
     * 民族
     */
    @OneToOne
    @JoinColumn(name = "nationid")
    private Nation nation;

    /**
     * 健康状态
     */
    @Column(name = "heath")
    private Integer heath;

    /**
     * 文化程度
     */
    @Column(name = "culture")
    @NotBlank
    private String culture;

    /**
     * 人员属性
     */
    @Column(name = "attr")
    @NotBlank
    private String attr;

    /**
     * 是否农业户口
     */
    @Column(name = "isfarm")
    private Integer isfarm;

    /**
     * 婚姻情况
     */
    @Column(name = "wedding")
    private Integer wedding;

    /**
     * 岗位
     */
    @OneToOne
    @JoinColumn(name = "positionid")
    private Position position;

    /**
     * 电话号码
     */
    @Column(name = "telephone")
    @NotBlank
    private String telephone;

    /**
     * 农合证号
     */
    @Column(name = "farmid")
    @NotBlank
    private String farmid;

    /**
     * 是否农村户口
     */
    @Column(name = "iscountry")
    private Integer iscountry;

    /**
     * 工作单位
     */
    @Column(name = "work")
    @NotBlank
    private String work;

    /**
     * 慢性病
     */
    @OneToOne
    @JoinColumn(name = "sortid")
    private CSort cSort;

    /**
     * 慢性病开始时间
     */
    @Column(name = "starttime")
    @CreationTimestamp
    private Timestamp starttime;

    /**
     * 慢性病结束时间
     */
    @Column(name = "endtime")
    @CreationTimestamp
    private Timestamp endtime;

    @Column(name = "enabled")
    private Boolean enabled;

    /**
     * 本地区域
     */
    @OneToOne
    @JoinColumn(name = "j_areaid")
    private J_Area j_area;

    /**
     * 迁出区域
     */
    @OneToOne
    @JoinColumn(name = "j_areaid_out")
    private J_Area j_area_out;

    /**
     * 附件id
     */
    @OneToOne
    @JoinColumn(name = "fileid")
    private HomeFile homeFile;

    /**
     * 支付编号
     */
    @Column(name = "paycode")
    private String paycode;

    /**
     * 规定的缴费起始时间
     */
    @Column(name = "paystarttime")
    @CreationTimestamp
    private Timestamp paystarttime;

    /**
     * 规定的最终缴费时间
     */
    @Column(name = "payendtime")
    @CreationTimestamp
    private Timestamp payendtime;

    /**
     * 是否参合
     */
    @Column(name = "isconsult")
    private Long isconsult;

    /**
     * 是否支付
     */
    @Column(name = "ispay")
    private Long ispay;

    /**
     * 上次报销金额
     */
    @Column(name = "amount")
    private String amount;

    /**
     * 支付方式
     */
    @Column(name = "paytype")
    private Long paytype;

    /**
     * 支付时间
     */
    @Column(name = "paytime")
    @CreationTimestamp
    private Timestamp paytime;

    @Column(name = "pid")
    private Long pid;

    /**
     * 报销项目
     */
    @Column(name = "accountname")
    private String accountname;

    /**
     * 当前需缴费金额 即预报销金
     */
    @Column(name = "nowamount")
    private String nowamount;

    /**
     * 报销金额
     */
    @Column(name = "accountamount")
    private String accountamount;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Home home = (Home) o;
        return id.equals(home.id) &&
                name.equals(home.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}
